<template>
  <el-dialog :visible.sync="visible" width="500px" :title="$t('label_examine')" @close="resetForm">

    <el-form :model="formData" :rules="rules" ref="ruleForm" label-width="120px">

          <el-form-item :label="$t('label_audit_status')" prop="auditPass">
            <el-select v-model="formData.auditPass" style="width: 100%;" :placeholder="$t('label_tisp_order_review_status')">
              <el-option v-for="(item,index) in $enumOptions.ScheduleCheckStatusEnum" :key="index" :label="$t('ScheduleCheckStatusEnum__'+item)" :value="item"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item :label="$t('label_reject_reason')" prop="refuseReason" v-if="formData.auditPass==='REJECT'">
            <el-input v-model="formData.refuseReason" type="textarea" :placeholder="$t('label_tisp_reason_rejection')"></el-input>
          </el-form-item>
    </el-form>

    <div slot="footer" class="">
        <el-button type="primary" @click="submitForm">{{ $tt('label_confirm') }}</el-button>
        <el-button @click="resetForm">{{ $tt('label_cancel') }}</el-button>
      </div>
</el-dialog>
</template>

<script>

export default {
  name: 'settings',
  data() {
    return {
      visible: false,
      loading: false,
      formData:{
        orderIds:[],
        auditPass:'APPROVED',
        refuseReason:''
      },
      rules:{
        auditPass:[{ required: true, message: this.$t('label_tisp_order_review_status'), trigger: 'change' }],
        refuseReason:[{ required: true, message: this.$t('label_tisp_reason_rejection'), trigger: 'blur' }],
      },
    }
  },
  mounted() {
  },
  methods: {
    show(rows) {
      this.formData.orderIds = []
      rows.forEach(item=>{
        this.formData.orderIds.push(item.id)
      })
      this.visible = true
    },
    hide() {
      this.visible = false
    },
    submitForm() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          this.$ajax({
            url: "/oms-api/express/ExpressOrderInfoRpc/batchAudit.json",
            method: 'post',
            type:'json',
            data:{
              ...this.formData,
              auditPass:this.formData.auditPass==='APPROVED'
            },
            loading: true,
            success: (res) => {

              this.$emitPage('packetOrder=>manage', 'reload')
              this.resetForm()
              this.$message.success(this.$tt("tip_submit_success"))
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm() {
      this.visible = false
      this.$refs['ruleForm'].resetFields();
      this.formData = {
        orderIds:[],
        auditPass:'APPROVED',
        refuseReason:''
      }
      // this.$data.formData = this.$options.data().formData
    }
  }
}
</script>

<style lang="less" scoped>

</style>
